<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates the training data struct from a user supplied function</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fann-create-standard.html">fann_create_standard</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.fann-create-train.html">fann_create_train</a></div>
 <div class="up"><a href="ref.fann.html">Fann 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.fann-create-train-from-callback" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fann_create_train_from_callback</h1>
  <p class="verinfo">(PECL fann &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">fann_create_train_from_callback</span> &mdash; <span class="dc-title">Creates the training data struct from a user supplied function</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.fann-create-train-from-callback-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>fann_create_train_from_callback</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_data</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_input</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_output</code></span>
   , <span class="methodparam"><span class="type"><span class="type collable">collable</span></span> <code class="parameter">$user_function</code></span>
   )</div>

  <p class="para rdfs-comment">
   Creates the training data struct from a user supplied function. As the training data are numerable (data 1, data 2...),
   the user must write a function that receives the number of the training data set (input, output) and returns the set.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fann-create-train-from-callback-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">num_data</code></em></dt>

    <dd>

     <p class="para">
      The number of training data
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">num_input</code></em></dt>

    <dd>

     <p class="para">
      The number of inputs per training data
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">num_output</code></em></dt>

    <dd>

     <p class="para">
      The number of ouputs per training data
     </p>
    </dd>

   
   
    <dt>
<em><code class="parameter">user_function</code></em></dt>

    <dd>

     <p class="para">
      The user supplied function with following parameters:
      <ul class="simplelist">
       <li class="member"><em>num</em> - The number of the training data set</li>
       <li class="member"><em>num_input</em> - The number of inputs per training data</li>
       <li class="member"><em>num</em> - The number of ouputs per training dataThe number of inputs per training data</li>
      </ul>
     </p>
     <p class="para">
      The function should return an associative array with keys <em>input</em> and <em>output</em> and
      two array values of input and output.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fann-create-train-from-callback-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para"> Returns a train data <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> on success, or <strong><code>FALSE</code></strong> on error.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fann-create-train-from-callback-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3656">
    <p><strong>Example #1 <span class="methodname"><strong>fann_create_train_from_callback()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">create_train_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$num_data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"input"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"output"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;);<br />}<br /><br /></span><span style="color: #0000BB">$num_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$num_input&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$num_output&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$train_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fann_create_train_from_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$num_data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"create_train_callback"</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$train_data</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Do&nbsp;something&nbsp;with&nbsp;$train_data<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fann-create-train-from-callback-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.fann-read-train-from-file.html" class="function" rel="rdfs-seeAlso">fann_read_train_from_file()</a> - Reads a file that stores training data</span></li>
    <li class="member"><span class="function"><a href="function.fann-train-on-data.html" class="function" rel="rdfs-seeAlso">fann_train_on_data()</a> - Trains on an entire dataset for a period of time</span></li>
    <li class="member"><span class="function"><a href="function.fann-destroy-train.html" class="function" rel="rdfs-seeAlso">fann_destroy_train()</a> - Destructs the training data</span></li>
    <li class="member"><span class="function"><a href="function.fann-save-train.html" class="function" rel="rdfs-seeAlso">fann_save_train()</a> - Save the training structure to a file</span></li>
   </ul>
  </p>
 </div>



</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.fann-create-standard.html">fann_create_standard</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.fann-create-train.html">fann_create_train</a></div>
 <div class="up"><a href="ref.fann.html">Fann 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
